package com.dailywork.basepro.thread.variable;

/**
 * volatile�ؼ��ֵ�ʹ��
 *
 * @author lhy
 * @time 2017.12.23
 */
public class RunThread extends Thread {

    // ����˴���ʹ��volatile�ؼ���,��ô����ִ�н���,�߳�Ҳ������ֹ,��Ϊ�̵߳�����ȡֵ�����ڴ���,�ͳ�������Ķ����޹�
    private volatile boolean isRunning = true;

    private void setRunning(boolean isRunning) {
        this.isRunning = isRunning;
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        System.out.println("����run����...");
        while (isRunning == true) {
            boolean a = isRunning;
        }
        System.out.println("�߳���ֹ...");
    }

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        RunThread rt = new RunThread();
        rt.start();
        Thread.sleep(3000);
        rt.setRunning(false);
        System.out.println("isRunning��ֵ�Ѿ���������false");
        Thread.sleep(1000);
        System.out.println(rt.isRunning);
    }
}
